local skel = fk.CreateSkill {
  name = "emo__zanghua",
  dynamic_desc = function (self, player, lang)
    if player:getMark("emo__caiqing_remove") ~= 0 then
      return "emo__zanghua_remove"
    end
  end,
}

Fk:loadTranslationTable{
  ["emo__zanghua"] = "葬花",
  [":emo__zanghua"] = "出牌阶段限一次，你可选择一项：<br>"..
  "①吟诵：弃置一张手牌，从牌堆摸一张延时锦囊牌，视为使用【无中生有】。<br>"..
  "②才情：弃置一张♣牌，指定一名角色，直到其回合结束：当其使用装备牌时失去一点体力。",

  [":emo__zanghua_remove"] = "出牌阶段限一次，你可弃置一张手牌，从牌堆摸一张延时锦囊牌，视为使用【无中生有】。",

  ["emo__yinsong"] = "吟诵",
  ["#emo__yinsong"] = "弃置一张手牌，从牌堆摸一张延时锦囊牌，视为使用【无中生有】",
  ["emo__caiqing"] = "才情",
  ["#emo__caiqing"] = "弃置一张♣牌，指定一名角色，直到其回合结束：当其使用装备牌时失去一点体力",

  ["@@emo__caiqing"] = "才情",

  ["$emo__zanghua1"] = "我既葬得了花，自然也就能葬得了你们",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  card_num = 1,
  interaction = function (self, player)
    local all_choices = {"emo__yinsong", "emo__caiqing"}
    local choices = table.simpleClone(all_choices)
    if player:getMark("emo__caiqing_remove") ~= 0 then
      table.remove(choices, 2)
    end
    return UI.ComboBox{ choices = choices, all_choices = all_choices }
  end,
  prompt = function (self)
    if self.interaction.data then
      return "#" .. self.interaction.data
    end
    return " "
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  card_filter = function (self, player, to_select, selected)
    local card = Fk:getCardById(to_select)
    if #selected == 0 and not player:prohibitDiscard(card) then
      if self.interaction.data == "emo__caiqing" then
        return card.suit == Card.Club
      else
        return table.contains(player:getCardIds("h"), to_select)
      end
    end
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected_cards == 1 and self.interaction.data == "emo__caiqing"
  end,
  feasible = function (self, player, selected, selected_cards, card)
    if #selected_cards == 1 then
      return self.interaction.data == "emo__yinsong" or #selected == 1
    end
  end,
  on_use = function (self, room, use)
    local player = use.from
    room:throwCard(use.cards, skel.name, player, player)
    if self.interaction.data == "emo__yinsong" then
      if player.dead then return end
      local ids = room:getCardsFromPileByRule(".|.|.|.|.|delayed_trick")
      if #ids > 0 then
        room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skel.name)
      end
      local card = Fk:cloneCard("ex_nihilo")
      card.skillName = skel.name
      if not player.dead and player:canUseTo(card, player) then
        room:useCard{from = player, tos = {player}, card = card}
      end
    else
      room:addPlayerMark(player, "emo__caiqing_count")
      local to = use.tos[1]
      room:setPlayerMark(to, "@@emo__caiqing", 1)
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and data.card.type == Card.TypeEquip and not target.dead and target:getMark("@@emo__caiqing") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, skel.name)
  end,
})

skel:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__caiqing") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__caiqing", 0)
  end,
})

return skel
